import VueRouter from "vue-router";
import Home from "../views/Home.vue";

const routes = [
  {
    path: "/",
    name: "home",
    component: Home
  },
  {
    path: "/about",
    name: "about",
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/About.vue")
  }
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes
});

// 页面跳转拦截上个页面所有有请求
window.__axiosCancelArr = [];
router.beforeEach((to, from, next) => {
  if (window.__axiosCancelArr && window.__axiosCancelArr.length) {
    window.__axiosCancelArr.forEach((item, index) => {
      item.cancel("axiosCancel");
      window.__axiosCancelArr.splice(index, 1);
    });
  }
  next();
});
export default router;
